VARIABLES and ASSIGNMENT

See also the Lua reference manual

Lua is a case sensitive language. Variable-names consist of upper- or lower-case letters, underscores or digits, but may not start with a digit. RiscLua also permits the characters ! $ ? @ `. Variable-names may not be reserved words. Variables either have global scope, in which case their values are held in the table _G, or they have local scope. A global variable requires no declaration. A variable or list of variables can be declared local with a local-declaration. In which case they may be followed by an attribute, <const> or <close>. Only one variable in such a list can have the <close> attribute. The scope of the variables so declared starts after the declaration and continues to the end of the innermost block containing the declaration. It may be masked within sub-blocks by further local-declarations that use the same variable name.

Variables are assigned values by assignment statements. These take the form

  <left-hand-side> = <right-hand-side>
where on the left is a comma-separated list of variable-names, and on the right is a comma-separated list of expressions. If the number of items on each side do not match, excess expressions are neglected or excess variables are assigned the value nil. If the assignment statement is preceded by the word local it is a local-declaration for the variables on the left-hand-side. Another joint assignment/local-declaration, not part of standard Lua, has the form

   local <left-hand-side> in <table-expression>
which looks up in the table given by the right-hand-side the values to be assigned to the left-hand-side. However attributes do not signify in this case.

A single-assignment statement of the form

  <left-hand-side> = <left-hand-side> <op> <right-hand-side>
can be written as


  <left-hand-side> <op> = <right-hand-side>
when op is one of
             ..  +  -  *  / //  ^ %  &  |  ~  <<  >>